//package com.tn.controller.trace;
//
//
//import com.influxdb.query.FluxRecord;
//import com.influxdb.query.FluxTable;
//import com.tn.config.InfluxBean;
//import com.tn.controller.alarm.common.model.CommonVO;
//
//import com.tn.controller.trace.dto.TraceReq;
//
//import lombok.extern.slf4j.Slf4j;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//
//import java.text.SimpleDateFormat;
//import java.util.*;
//
///**
// * 磅房controller
// *
// * @program: tn_aucy_java
// * @author: yangjiayao
// * @create: 2021/11/16
// */
//@Slf4j
//@RestController
//@RequestMapping("/aucy")
//public class TraceController {
//    @Autowired
//    private InfluxBean influxBean;
//
//
//    /**
//     * 历史轨迹
//     * @param req
//     * @return
//     */
//    @RequestMapping(value = "/trace", method = {RequestMethod.POST}, produces = "application/json")
//    public CommonVO<Object> trace(@RequestBody TraceReq req)
//    {
//        List<String> licenses = req.getLicense();
//        Map returnMap=new HashMap();
//        for (String license : licenses) {
//            List<Map>list=new ArrayList<>();
//            String startTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(req.getStartTime());
//            String endTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(req.getEndTime());
//            String query=
//                    "from(bucket: \"donn\")\n" +
//                            "              |> range(start:%s,stop:%s)\n" +
//                            "              |> filter(fn: (r) => r[\"_measurement\"] == \"trace\")\n" +
//                            "                |> filter(fn: (r) => r[\"license\"] == \"%s\")\n" +
//                            "              |> filter(fn: (r) => r[\"_field\"] == \"position\")"   ;
//            String flux=String.format(query,startTime,endTime,license);
//            List<FluxTable> fluxTables = influxBean.queryTable(flux);
//            for (FluxTable fluxTable : fluxTables) {
//                List<FluxRecord> records = fluxTable.getRecords();
//                for (FluxRecord record : records) {
//                    Map<String,Object>map=new HashMap<>();
//                    map.put("license",license);
//                    map.put("position",record.getValue());
//                    Date date = new Date(record.getTime().toEpochMilli());
//                    String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
//                    map.put("time", format);
//                    list.add(map);
//                }
//            }
//            returnMap.put(license,list);
//        }
//        return new CommonVO<>(returnMap);
//    }
//
//
//    /**
//     * 热力图
//     * @param req
//     * @return
//     */
//    @RequestMapping(value = "/thermodynamic-chart", method = {RequestMethod.POST}, produces = "application/json")
//    public CommonVO<Object> thermodynamicChart(@RequestBody TraceReq req)
//    {
//        List<String>list=new ArrayList<>();
//        String query="";
//        String flux="";
//        String time = req.getTime();
//        if(time.contains("h")){
//            String[] hs = time.split("h");
//            long newTIme=Long.valueOf(hs[0]);
//            query=
//                    "from(bucket: \"donn\")\n" +
//                            "              |> range(start:-%dh)\n" +
//                            "              |> filter(fn: (r) => r[\"_measurement\"] == \"trace\")\n" +
//                            "              |> filter(fn: (r) => r[\"_field\"] == \"position\")"   ;
//            flux=String.format(query,newTIme);
//        } else if (time.contains("m")) {
//            String[] hs = time.split("m");
//            long newTIme=Long.valueOf(hs[0]);
//            query=
//                    "from(bucket: \"donn\")\n" +
//                            "              |> range(start:-%dm)\n" +
//                            "              |> filter(fn: (r) => r[\"_measurement\"] == \"trace\")\n" +
//                            "              |> filter(fn: (r) => r[\"_field\"] == \"position\")"   ;
//            flux=String.format(query,newTIme);
//
//        } else if (time.contains("s")) {
//            String[] hs = time.split("s");
//            long newTIme=Long.valueOf(hs[0]);
//            query=
//                    "from(bucket: \"donn\")\n" +
//                            "              |> range(start:-%ds)\n" +
//                            "              |> filter(fn: (r) => r[\"_measurement\"] == \"trace\")\n" +
//                            "              |> filter(fn: (r) => r[\"_field\"] == \"position\")"   ;
//            flux=String.format(query,newTIme);
//
//        } else if (time.contains("d")) {
//            String[] hs = time.split("d");
//            long newTIme=Long.valueOf(hs[0]);
//            query=
//                    "from(bucket: \"donn\")\n" +
//                            "              |> range(start:-%dd)\n" +
//                            "              |> filter(fn: (r) => r[\"_measurement\"] == \"trace\")\n" +
//                            "              |> filter(fn: (r) => r[\"_field\"] == \"position\")"   ;
//            flux=String.format(query,newTIme);
//        } else if (time.contains("mo")) {
//            String[] hs = time.split("mo");
//            long newTIme=Long.valueOf(hs[0]);
//            query=
//                    "from(bucket: \"donn\")\n" +
//                            "              |> range(start:-%dmo)\n" +
//                            "              |> filter(fn: (r) => r[\"_measurement\"] == \"trace\")\n" +
//                            "              |> filter(fn: (r) => r[\"_field\"] == \"position\")"   ;
//            flux=String.format(query,newTIme);
//        }else if (time.contains("y")) {
//            String[] hs = time.split("y");
//            long newTIme=Long.valueOf(hs[0]);
//            query=
//                    "from(bucket: \"donn\")\n" +
//                            "              |> range(start:-%dy)\n" +
//                            "              |> filter(fn: (r) => r[\"_measurement\"] == \"trace\")\n" +
//                            "              |> filter(fn: (r) => r[\"_field\"] == \"position\")"   ;
//            flux=String.format(query,newTIme);
//        }
//
//        List<FluxTable> fluxTables = influxBean.queryTable(flux);
//            for (FluxTable fluxTable : fluxTables) {
//                List<FluxRecord> records = fluxTable.getRecords();
//                for (FluxRecord record : records) {
//                    list.add(record.getValue().toString());
//                }
//            }
//
//        return new CommonVO<>(list);
//    }
//
//}
